<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        *{padding:0;margin:0;box-sizing: border-box;}
        ul{
            list-style: none;
            margin-left: 50px;
            width: 200px;
            background-color: antiquewhite;
        }
        li{
            padding: 10px 0;
            text-align: center;
            cursor: pointer;
        }
        .active{
            background-color: red;
            color: white;
        }
    </style>
</head>

<body>
    <div id="root">
        <p :class="obj">
            窗前明月光
        </p>
        <ul>
            <li :class="{active:currentIndex===index}" v-for="(item,index) in list" :key="item.id" @click="change(index)">
                {{item.title}}
            </li>
        </ul>
    </div>
    <script>
        const VM = new Vue({
            el: '#root',
            data: {
                obj: { one: true, two: 22 },
                basic: "zero",
                currentIndex:0,
                list: [
                    { id: 1001, title: '母婴' },
                    { id: 2021, title: '家电' },
                    { id: 3789, title: '医用' },
                    { id: 4214, title: '手机' },
                    { id: 532, title: '直播' },
                    { id: 699, title: '游戏' },
                    { id: 732, title: '酒水' },
                    { id: 8123, title: '娱乐' },
                    { id: 991, title: '美食' },
                    { id: 101, title: '财经' }
                ],
            },
            methods: {
                change(index){
                    this.currentIndex = index;
                }
            },
        });
    </script>
</body>

</html>